package com.zy.chat.controller;


import com.zy.chat.entity.ChatGroup;
import com.zy.chat.service.GroupService;
import com.zy.chat.vo.GroupResult;
import com.zy.chat.vo.RequestParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(value = "groupcontroller")
public class GroupController {


    @Autowired
    private GroupService groupService;
    @GetMapping(value = "/group/{username}")
    public ResponseEntity<ChatGroup> selectByUserId(@PathVariable(value = "username")String username) throws Exception{
        ChatGroup chatGroup=this.groupService.selectByUserId(username);
        return new ResponseEntity<ChatGroup>(chatGroup, HttpStatus.OK);
    }


    @PostMapping("/list")
    public ResponseEntity<GroupResult> search(@RequestBody RequestParams params) {
        return new ResponseEntity<GroupResult>( groupService.search(params),HttpStatus.OK);
    }

    @GetMapping("/suggestion/{key}")
    public ResponseEntity<List<String>> getSuggestion(@PathVariable(value = "key") String key) throws  Exception{
        return new ResponseEntity<List<String>>(groupService.getSuggestion(key),HttpStatus.OK);
    }
}
